class Solution {
    public String reverseWords(String s) {
        char []result=s.toCharArray();
        int n=result.length;
        int i=0;
        while(i<n)
        {
            int left=i;
            while(i<n&&result[i]!=' ')
            {
                i++;
            }
            reverse(result,left,i-1);
            while(i<n&&s.charAt(i)==' ')
            {
                i++;
            }
        }
        return new String(result);
    }
    void reverse(char []s,int left,int right)
    {
        while(left<right)
        {
            char temp=s[left];
            s[left]=s[right];
            s[right]=temp;
            left++;
            right--;
        }
    }
}

